/*
 * @Author: yixin 
 * @Date: 2019-11-25 14:15:38 
 * @Last Modified by: yixin
 * @Last Modified time: 2019-12-09 11:39:48
 * 车辆油耗
 */

import React, { PureComponent } from "react"
import { withRouter } from "react-router"
import styles from './carOil.less'
import Header from '@/components/header'
import Pie from '@/components/pie'
import { equipOneOil } from '@/services'

class CarOil extends PureComponent {

  constructor(props){
    super(props);
  }

  componentDidMount(){
    this.renderPie()
  }

  renderPie = async () => {
    try {
      const data = await equipOneOil({ equipCode: this.props.location.state.equipCode, ...this.props.location.state.worktime });
      if(data.code === 200){
        let series = [
          { name: '行驶', value: data.data.oil.driveOil, itemStyle: { color: '#D0B17E' } },
          { name: '驻车', value: data.data.oil.parkOil, itemStyle: { color: '#CCCCCC' } },
          { name: '泵送', value: data.data.oil.pumpOil, itemStyle: { color: '#2DD5B8' } },
          { name: '转场', value: data.data.oil.switchOil, itemStyle: { color: '#666666' } },
          { name: '待料', value: data.data.oil.awaitOil, itemStyle: { color: '#E65751' } }
        ];
        this.pie && this.pie.init([
          { data: [{ name: '总工时', value: data.data.oil.driveOil+data.data.oil.parkOil+data.data.oil.pumpOil+data.data.oil.switchOil+data.data.oil.awaitOil }] },
          { data: series }
        ])
      }
    } catch (error) {
      
    }
  }  
  
  render(){
    return (
      <div>
        <Header>{this.props.location.state.equipCode}</Header>
        <Pie ref={el=>{ this.pie = el }} unit="L" />
      </div>
    )
  }
}
export default withRouter(CarOil)